{% extends 'base.html' %}
{% block title %}{% endblock %}
{% load staticfiles %}
{% block custom_bread %}
    <section>
        <div class="wp">
            <div class="crumbs">
                <ul>
                    <li><a href="/">首页</a>></li>
                    <li><a href="{% url 'course:course_list' %}">课程</a>></li>
                    <li>课程详情</li>
                </ul>
            </div>
        </div>
    </section>
{% endblock %}


{% block content %}
    <section>
        <div class="wp">
            <div class="groupPurchase_detail detail">
                <div class="toppro">
                    <div class="left">
                        <div class="picbox">
                            <div class="tb-booth tb-pic">

                                <img width="440px" height="445px" src="{{ MEDIA_URL }}{{ course.image }}" class="jqzoom"
                                     style="position: relative"/>
                                {% if course.is_member == 1 %}
                                    <img src="/static/images/vip2.png"
                                         style="position: absolute; top: 0px;left: 10px;width:50px;height:50px"/>
                                {% endif %}

                            </div>

                        </div>
                        <div class="des">
                            <h1>{{ course.name }}</h1>
                            <span class="key">{{ course.desc }}</span>
                            <div class="prize">
                                <span class="fl">难度：<i class="key">{{ course.get_degree_display }}</i></span>
                                <span class="fr">订阅人数：{{ course.fav_nums }}</span>
                            </div>
                            <ul class="parameter">
                                <li><span
                                        class="pram word3">时长：</span><span>{{ course.learn_times }}</span>
                                </li>
                                <li><span class="pram word3">热量：</span><span>{{ course.heat }}</span>
                                </li>

                                {% for user_course in course.get_learn_users %}
                                    <span class="pic"><img width="40" height="40"
                                                           src="{{ MEDIA_URL }}{{ user_course.user.image }}"/></span>
                                {% endfor %}
                                </li>
                            </ul>
                            <div class="btns">
                                <a class="btn colectgroupbtn" id="jsLeftBtn">
                                    {% if has_fav_course %}已订阅{% else %}订阅{% endif %}
                                </a>
                                {#                                <div class="buy btn"><a style="color: white" href="{% url 'course:course_info' course.id %}">开始学习</a></div>#}
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </section>
    <section>
        <div class="wp">
            <div class="list groupPurchase_detail_pro">
                <div class="left layout">
                    <div class="head">
                        <ul class="tab_header">
                            <li class="active">课程详情</li>
                        </ul>
                    </div>
                    <div class="tab_cont tab_cont1">
                        {% autoescape off %}
                            {{ course.detail }}
                        {% endautoescape %}
                    </div>
                    <div class="tab_cont tab_cont2">
                        <div class="comment">
                            <div class="comenlist">

                            </div>
                        </div>
                    </div>
                </div>
                {#			<div class="right layout">#}
                {#				<div class="head">相关课程推荐</div>#}
                {#                <div class="group_recommend">#}
                {#                    {% for relate_course in relate_coures %}#}
                {#                        <dl>#}
                {#                            <dt>#}
                {#                                <a target="_blank" href="">#}
                {#                                    <img width="240" height="220" class="scrollLoading" src="{{ MEDIA_URL }}{{ relate_course.image }}"/>#}
                {#                                </a>#}
                {#                            </dt>#}
                {#                            <dd>#}
                {#                                <a target="_blank" href=""><h2> {{ relate_course.name }}</h2></a>#}
                {#                                <span class="fl">学习时长：<i class="key">{{ relate_course.learn_times }}</i></span>#}
                {#                            </dd>#}
                {#                        </dl>#}
                {#                    {% endfor %}#}
                {##}
                {##}
                {#                </div>#}
                {#			</div>#}
            </div>
        </div>
    </section>
{% endblock %}

{% block custom_js %}
    <script type="text/javascript">
        //收藏分享
        function add_fav(current_elem, fav_id, fav_type) {
            var  a='{{ course.is_member }}';
            var user="{{ request.user.is_member }}";
            if (a=="True"){
                if (user!="True"){
                    alert("不是会员不能订阅，请去个人中心中开通会员！")
                    return false
                }
            }


            $.ajax({
                cache: false,
                type: "POST",
                url: "{% url "teacher:addfav" %}",
                data: {'fav_id': fav_id, 'fav_type': fav_type},
                async: true,
                beforeSend: function (xhr, settings) {
                    xhr.setRequestHeader("X-CSRFToken", "{{ csrf_token }}");
                },
                success: function (data) {
                    if (data.status == 'fail') {
                        if (data.msg == '用户未登录') {
                            window.location.href = "/login/";
                        } else {
                            alert(data.msg)
                        }

                    } else if (data.status == 'success') {
                        current_elem.text("已订阅")
                    }
                },
            });
        }

        $('#jsLeftBtn').on('click', function () {

            add_fav($(this), {{ course.id }}, 1);
        });

        {#$('#jsRightBtn').on('click', function(){#}
        {#    console.log(90)#}
        {#    add_fav($(this), {{ course.course_org.id }}, 2);#}


    </script>

{% endblock %}